package com.platform.consumer.function;

import com.platform.common.bean.User;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.service.GenericService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 *  泛化调用
 */
@RestController
public class QueryUserGerenicFunction {

    private static final Logger logger = LoggerFactory.getLogger(QueryUserGerenicFunction.class);


    @Reference(generic = true,interfaceName = "com.platform.common.interfaces.IQueryUserFunction")
    private GenericService queryUserFunction;

    @RequestMapping("/queryUserName")
    public String queryUserName(int userId){

        Map<String,Object> resultMap= (Map<String, Object>) queryUserFunction.$invoke("queryUserById",new String[] { "int" }, new Object[] { userId });

       if(null == resultMap){
           return null;
       }
        logger.info(resultMap.toString());
        return resultMap.get("name").toString();
    }

}
